<?php
// +----------------------------------------------------------------------
// | Fanwe 方维订餐小秘书商业系统
// +----------------------------------------------------------------------
// | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 云淡风轻(88522820@qq.com)
// +----------------------------------------------------------------------

class kviewModule extends StoreBaseModule
{	
	public function index()
	{
		$id = intval($_REQUEST['id']);
		
		if(check_ipop_limit(get_client_ip(),"recount_supplier_location",1200,$id))
		{
			recount_supplier_data_count($id,"tuan");
			recount_supplier_data_count($id,"youhui");
			recount_supplier_data_count($id,"daijin");
			recount_supplier_data_count($id,"event");
			recount_supplier_data_count($id,"shop");
		}
		$GLOBALS['tmpl']->caching = true;
		$cache_id  = md5(MODULE_NAME.ACTION_NAME.$id);		
		if (!$GLOBALS['tmpl']->is_cached('store_kview.html', $cache_id))	
		{	
			$store_info = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."supplier_location where id = ".$id." and is_effect = 1");
			if(!$store_info)
			{
				showErr($GLOBALS['lang']['NO_STORE_INFO']);
			}		
			$store_info['online_info']=htmlspecialchars_decode($store_info['online_info']);
			$store_info['group_point'] = $GLOBALS['db']->getAll("select id,name from ".DB_PREFIX."point_group as pg left join ".DB_PREFIX."point_group_link as pgl on pg.id = pgl.point_group_id  where pgl.category_id = ".$store_info['deal_cate_id']." order by sort asc" );
			foreach($store_info['group_point'] as $kk=>$vv)
			{
				$store_info['group_point'][$kk]['avg_point'] =  round(floatval($GLOBALS['db']->getOne("select avg_point from ".DB_PREFIX."supplier_location_point_result where supplier_location_id = ".$store_info['id']." and group_id = ".$vv['id'])),1);
			}
			
			
			$tags = array();
			if($store_info['tags']){
				$ttags = explode(" ",$store_info['tags']);
				foreach($ttags as $tv){
					$tags[$tv]['name'] =  $tv;
					$tags[$tv]['code'] = $tv;
				}
			}
			$store_info['tags_list'] = $tags;
			//标签分组
			$tag_group = $GLOBALS['db']->getAll("select g.id,g.name,g.allow_vote from ".DB_PREFIX."tag_group as g left join ".DB_PREFIX."tag_group_link as gl on g.id = gl.tag_group_id where gl.category_id = ".$store_info['deal_cate_id']." order by g.sort");
	
			foreach($tag_group as $k=>$v)
			{
				$tags = $GLOBALS['db']->getAll("select tag_name,total_count from ".DB_PREFIX."supplier_tag where group_id = ".$v['id']." and supplier_location_id =".$store_info['id']." order by total_count desc limit 30");
				$tags_arr = array();
				foreach($tags as $kk=>$vv)
				{
					$vv['tag_name'] = trim($vv['tag_name']);
					if($vv['tag_name']!='')
					{
						$tags_arr[$kk]['url'] = url("store","index",array("tag"=>$vv['tag_name']));
						$tags_arr[$kk]['name'] = $vv['tag_name'];
						$tags_arr[$kk]['total_count'] = $vv['total_count'];
					}
				}	
				$tag_group[$k]['tags'] = $tags_arr;
			}	
			
			$store_info['tag_group'] = $tag_group;

			$cate_item = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."deal_cate where id = ".$store_info['deal_cate_id']);
			
			$site_nav[] = array('name'=>$GLOBALS['lang']['HOME_PAGE'],'url'=>url("index","index"));
			$site_nav[] = array('name'=>$GLOBALS['lang']['STORE_KTV_LIST'],'url'=>url("store","ktv"));
			$site_nav[] = array('name'=>$store_info['name'],'url'=>url("store","kview",array("id"=>$store_info['id'])));
			$GLOBALS['tmpl']->assign("site_nav",$site_nav);
			
			//分类
			$store_cate_list = $GLOBALS['db']->getAll("SELECT dct.* FROM ".DB_PREFIX."deal_cate_type_location_link dctl LEFT JOIN ".DB_PREFIX."deal_cate_type dct ON dct.id =dctl.deal_cate_type_id WHERE dctl.location_id=".$id);
			foreach($store_cate_list as $kkk=>$vvv){
				$store_cate_list[$kkk]['url'] = url("store","index",array("cid"=>$store_info['deal_cate_id'],"tid"=>$vvv['id']));
			}
			$GLOBALS['tmpl']->assign("store_cate_list",$store_cate_list);
			
			$seo_title = $store_info['seo_title']?$store_info['seo_title']:$store_info['name'];
			$GLOBALS['tmpl']->assign("page_title",$seo_title);
			$seo_keyword = $store_info['seo_keyword']?$store_info['seo_keyword']:$store_info['name'];
			$GLOBALS['tmpl']->assign("page_keyword",$seo_keyword.",");
			$seo_description = $store_info['seo_description']?$store_info['seo_description']:$store_info['name'];
			$GLOBALS['tmpl']->assign("page_description",$seo_description.",");
			$GLOBALS['tmpl']->assign("store_info",$store_info);
			$GLOBALS['tmpl']->assign("show_share",true);
			$GLOBALS['tmpl']->assign("show_fav",true);
			
			$json_location_data[] =  $store_info;
			$json_location_data = json_encode($json_location_data);
			$GLOBALS['tmpl']->assign("json_location_data",$json_location_data);
			
			
			//输出最新加入的商家
			$new_stores = $GLOBALS['db']->getAll("select id,name,address from ".DB_PREFIX."supplier_location where city_id = ".$GLOBALS['deal_city']['id']." and is_effect = 1 order by id desc limit 5");
			$GLOBALS['tmpl']->assign("new_stores",$new_stores);
			$rec_stores = $GLOBALS['db']->getAll("select id,name,address,avg_point,dp_count from ".DB_PREFIX."supplier_location where city_id = ".$GLOBALS['deal_city']['id']." and is_recommend = 1 and is_effect = 1 order by is_recommend desc limit 5");
			$GLOBALS['tmpl']->assign("rec_stores",$rec_stores);
			
			//现金券（前代金）
			$xianjin_sql_count = "select count(*) from ".DB_PREFIX."deal as d left join ".DB_PREFIX."deal_location_link as l on l.deal_id = d.id where d.is_delete = 0 and d.is_effect = 1 and d.is_shop = 2 and d.time_status in (0,1) and l.location_id = ".$id;
			$xianjin_count = $GLOBALS['db']->getOne($xianjin_sql_count);
			if($xianjin_count){
				$xianjin_html = kviewModule::ajax_get_xianjin($xianjin_count);
				$GLOBALS['tmpl']->assign("xianjin_count",$xianjin_count);
				$GLOBALS['tmpl']->assign("xianjin_html",$xianjin_html);
			}
			
			//订单
			$order_count = $GLOBALS['db']->getOne("SELECT count(*) FROM ".DB_PREFIX."supplier_location_order WHERE status in(0,1,2) AND sid=".$id);
			if($order_count > 0){
				$order_html = kviewModule::ajax_get_order($order_count);
				$GLOBALS['tmpl']->assign("order_count",$order_count);
				$GLOBALS['tmpl']->assign("order_html",$order_html);		
			}
			
			$conf_score=app_conf("USER_CT_ORDER_SCORE");
			$GLOBALS['tmpl']->assign("conf_score",$conf_score);
		}
		
		$GLOBALS['tmpl']->display("store_kview.html",$cache_id);	
	}
	
	
	
	function get_reivew_form($arr){
		$store_info['id'] =  $arr['id'];
		$store_info['deal_cate_id'] =  $arr['deal_cate_id'];
		if(intval($_REQUEST['is_ajax'])==1){
			if(intval($_REQUEST['deal_cate_id'])> 0){
				$store_info['deal_cate_id'] = intval($_REQUEST['deal_cate_id']);
			}
			if(intval($_REQUEST['id'])>0){
				$store_info['id'] = intval($_REQUEST['id']);
			}
		}
		//点评的内容与分组
		$point_group = $GLOBALS['db']->getAll("select pg.name,pg.id from ".DB_PREFIX."point_group as pg left join ".DB_PREFIX."point_group_link as pgl on pg.id = pgl.point_group_id where pgl.category_id = ".intval($store_info['deal_cate_id'])." order by pg.sort asc");
		$store_info['point_group'] = $point_group;
		
		//点评标签分组
		$tag_group = $GLOBALS['db']->getAll("select tg.name,tg.id,tg.preset from ".DB_PREFIX."tag_group  as tg left join ".DB_PREFIX."tag_group_link as tgl on tg.id = tgl.tag_group_id where tgl.category_id = ".intval($store_info['deal_cate_id'])." and tg.allow_dp = 1 order by tg.sort asc");
		foreach($tag_group as $k=>$v)
		{
			$preset = $GLOBALS['db']->getOne("select mtg.preset from ".DB_PREFIX."supplier_tag_group_preset as mtg where mtg.supplier_location_id = ".$store_info['id']." and mtg.group_id = ".$v['id'] );
			if($preset)
			$tag_group[$k]['preset_tags'] = explode(" ",$preset);
			else
			$tag_group[$k]['preset_tags'] = explode(" ",$v['preset']);
		}
		$store_info['dp_tag_group'] = $tag_group;
		$GLOBALS['tmpl']->assign("store_info",$store_info);
		if(intval($_REQUEST['is_ajax'])==1)
			echo $GLOBALS['tmpl']->fetch("inc/review/review_form.html");
		else
			return $GLOBALS['tmpl']->fetch("inc/review/review_form.html");
	}
	
	
	
	function load_store_navs()
	{
		$location_id = intval($_REQUEST['id']);
		//与商户相关的菜单：团购,优惠,代金,活动
//		$t_sql = "select count(*) from ".DB_PREFIX."deal as d 
//					left join ".DB_PREFIX."deal_location_link as l on l.deal_id = d.id 
//					where d.is_delete = 0 and d.is_effect = 1 and d.is_shop = 0 and d.time_status in (0,1) and l.location_id = ".$location_id;
//		
//		$d_sql = "select count(*) from ".DB_PREFIX."deal as d 
//					left join ".DB_PREFIX."deal_location_link as l on l.deal_id = d.id 
//					where d.is_delete = 0 and d.is_effect = 1 and d.is_shop = 2 and d.time_status in (0,1) and l.location_id = ".$location_id;
//
//
//		$time_condition = '  and (y.end_time = 0 or y.end_time > '.get_gmtime().' ) ';
//		$y_sql = "select count(*) from ".DB_PREFIX."youhui as y 
//					left join ".DB_PREFIX."youhui_location_link as l on l.youhui_id  = y.id 
//					where y.is_effect = 1 and l.location_id = ".$location_id.$time_condition;
//		
//		$e_sql = "select count(*) from ".DB_PREFIX."event as e 
//					left join ".DB_PREFIX."event_location_link as l on l.event_id  = e.id 
//					where e.is_effect = 1 and l.location_id = ".$location_id;
//		
//		$tcount = $GLOBALS['db']->getOne($t_sql);
//		$dcount = $GLOBALS['db']->getOne($d_sql);
//		$ycount = $GLOBALS['db']->getOne($y_sql);
//		$ecount = $GLOBALS['db']->getOne($e_sql);
//		
		$location_info = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."supplier_location where id = ".$location_id);
		$tcount = $location_info['tuan_count'];
		$dcount = $location_info['daijin_count'];
		$ycount = $location_info['youhui_count'];
		$ecount = $location_info['event_count'];
		$scount = $location_info['shop_count'];
		//if($tcount>0)
		{
			$navs[] = array("name"=>"团购","location_id"=>$location_id,"type"=>"t","count"=>$tcount);
		}
		//if($ycount>0)
		{
			$navs[] = array("name"=>"优惠券","location_id"=>$location_id,"type"=>"y","count"=>$ycount);
		}
		//if($dcount>0)
		{
			$navs[] = array("name"=>"现金券","location_id"=>$location_id,"type"=>"d","count"=>$dcount);
		}
		//if($ecount>0)
		{
			$navs[] = array("name"=>"活动","location_id"=>$location_id,"type"=>"e","count"=>$ecount);
		}
		$GLOBALS['tmpl']->assign("navs",$navs);
		return $GLOBALS['tmpl']->fetch("inc/store_navs.html");
	}
	
	public function ajax_get_content()
	{
		require_once APP_ROOT_PATH."app/Lib/page.php";
		$type = addslashes($_REQUEST['type']);
		$location_id = intval($_REQUEST['id']);
		$page_size = 1; 
		$upara = array(
			"type"=>$type,
			"id"=>$location_id
		);
		//分页
		$page = intval($_REQUEST['p']);
		if($page==0)
			$page = 1;
		$limit = (($page-1)*$page_size).",".$page_size;		
		
		switch($type)
		{
			case "t":
				//团购
				$t_sql_count = "select count(*) from ".DB_PREFIX."deal as d 
					left join ".DB_PREFIX."deal_location_link as l on l.deal_id = d.id 
					where d.is_delete = 0 and d.is_effect = 1 and d.is_shop = 0 and d.time_status in (0,1) and l.location_id = ".$location_id;
				$t_sql = "select id,name,img,uname,current_price,origin_price,buy_count from ".DB_PREFIX."deal as d 
					left join ".DB_PREFIX."deal_location_link as l on l.deal_id = d.id 
					where d.is_delete = 0 and d.is_effect = 1 and d.is_shop = 0 and d.time_status in (0,1) and l.location_id = ".$location_id." order by d.sort desc limit ".$limit;
			
				$result_list = $GLOBALS['db']->getAll($t_sql);
				$count = $GLOBALS['db']->getOne($t_sql_count);
				foreach($result_list as $k=>$v)
				{
					$list[$k]['id'] = $v['id'];
					$list[$k]['name'] = $v['name'];
					$list[$k]['image'] = $v['img'];	
					$list[$k]['buy_count'] = $v['buy_count'];
					$list[$k]['format_origin_price']=round($v['origin_price'],2);
					$list[$k]['format_current_price']=format_price($v['current_price']);	
					$list[$k]['discount'] = round(($v['current_price']/$v['origin_price'])*10,2);
					if($v['uname']=='')				
					$list[$k]['url'] = url("tuan","deal",array("id"=>$v['id']));	
					else
					$list[$k]['url'] = url("tuan","deal",array("id"=>$v['uname']));		
				}				
				break;
			case "d":
				//代金
				$d_sql_count = "select count(*) from ".DB_PREFIX."deal as d 
					left join ".DB_PREFIX."deal_location_link as l on l.deal_id = d.id 
					where d.is_delete = 0 and d.is_effect = 1 and d.is_shop = 2 and d.time_status in (0,1) and l.location_id = ".$location_id;
				$d_sql = "select id,name,img,uname,current_price,origin_price,buy_count,brief,max_bought from ".DB_PREFIX."deal as d 
					left join ".DB_PREFIX."deal_location_link as l on l.deal_id = d.id 
					where d.is_delete = 0 and d.is_effect = 1 and d.is_shop = 2 and d.time_status in (0,1) and l.location_id = ".$location_id." order by d.sort desc limit ".$limit;
				$result_list = $GLOBALS['db']->getAll($d_sql);
				$count = $GLOBALS['db']->getOne($d_sql_count);
				foreach($result_list as $k=>$v)
				{
					$list[$k]['id'] = $v['id'];
					$list[$k]['name'] = $v['name'];
					$list[$k]['image'] = $v['img'];
					$list[$k]['buy_count'] = $v['buy_count'];
					if($v['max_bought']>0)
						$list[$k]['can_count'] = $v['max_bought']-$v['buy_count'];
					$list[$k]['brief'] = $v['brief'];
					$list[$k]['format_origin_price']=round($v['origin_price'],2);
					$list[$k]['format_current_price']=format_price($v['current_price']);	
					$list[$k]['discount'] = round(($v['current_price']/$v['origin_price'])*10,2);				
					if($v['uname']=='')				
					$list[$k]['url'] = url("store","ydetail",array("id"=>$v['id']));	
					else
					$list[$k]['url'] = url("store","ydetail",array("id"=>$v['uname']));	
				}		
				break;
			case "s":
				//商城
				$d_sql_count = "select count(*) from ".DB_PREFIX."deal as d 
					left join ".DB_PREFIX."deal_location_link as l on l.deal_id = d.id 
					where d.is_delete = 0 and d.is_effect = 1 and d.is_shop = 1 and d.time_status in (0,1) and l.location_id = ".$location_id;
				$d_sql = "select id,name,img,uname from ".DB_PREFIX."deal as d 
					left join ".DB_PREFIX."deal_location_link as l on l.deal_id = d.id 
					where d.is_delete = 0 and d.is_effect = 1 and d.is_shop = 1 and d.time_status in (0,1) and l.location_id = ".$location_id." order by d.sort desc limit ".$limit;
				$result_list = $GLOBALS['db']->getAll($d_sql);
				$count = $GLOBALS['db']->getOne($d_sql_count);
				foreach($result_list as $k=>$v)
				{
					$list[$k]['id'] = $v['id'];
					$list[$k]['name'] = $v['name'];
					$list[$k]['image'] = $v['img'];	
					if($v['uname']=='')				
					$list[$k]['url'] = url("shop","goods",array("id"=>$v['id']));	
					else
					$list[$k]['url'] = url("shop","goods",array("id"=>$v['uname']));		
				}		
				break;
			case "y":				
				//优惠
				$time_condition = '  and (y.end_time = 0 or y.end_time > '.get_gmtime().' ) ';
				$y_sql_count = "select count(*) from ".DB_PREFIX."youhui as y 
					left join ".DB_PREFIX."youhui_location_link as l on l.youhui_id  = y.id 
					where y.is_effect = 1 and l.location_id = ".$location_id.$time_condition;
				$y_sql = "select id,name,icon,list_brief,view_count from ".DB_PREFIX."youhui as y 
					left join ".DB_PREFIX."youhui_location_link as l on l.youhui_id  = y.id 
					where y.is_effect = 1 and l.location_id = ".$location_id.$time_condition." order by y.sort desc limit ".$limit;
				$result_list = $GLOBALS['db']->getAll($y_sql);
				$count = $GLOBALS['db']->getOne($y_sql_count);
				foreach($result_list as $k=>$v)
				{
					$list[$k]['id'] = $v['id'];
					$list[$k]['name'] = $v['name'];
					$list[$k]['image'] = $v['icon'];
					$list[$k]['view_count'] = $v['view_count'];
					$list[$k]['list_brief'] = $v['list_brief'];	
					$list[$k]['url'] = url("store","fdetail",array("id"=>$v['id']));		
				}		
				break;
			case "e":
				//活动
				$e_sql_count = "select count(*) from ".DB_PREFIX."event as e 
					left join ".DB_PREFIX."event_location_link as l on l.event_id  = e.id 
					where e.is_effect = 1 and l.location_id = ".$location_id;
				$e_sql = "select id,name,icon,brief,submit_count from ".DB_PREFIX."event as e 
					left join ".DB_PREFIX."event_location_link as l on l.event_id  = e.id 
					where e.is_effect = 1 and l.location_id = ".$location_id." order by e.sort desc limit ".$limit;
				$result_list = $GLOBALS['db']->getAll($e_sql);
				$count = $GLOBALS['db']->getOne($e_sql_count);
				foreach($result_list as $k=>$v)
				{
					$list[$k]['id'] = $v['id'];
					$list[$k]['name'] = $v['name'];
					$list[$k]['image'] = $v['icon'];
					$list[$k]['brief'] = $v['brief'];
					$list[$k]['submit_count'] = $v['submit_count'];	
					$list[$k]['url'] = url("store","edetail",array("id"=>$v['id']));		
				}				
				break;
		}
		$GLOBALS['current_url'] = url("store","view#ajax_get_content",$upara);		
		$page = new Page($count,$page_size);   //初始化分页对象 		
		$p  =  $page->show();
		$GLOBALS['tmpl']->assign('pages',$p);
		$GLOBALS['tmpl']->assign('type',$type);
		$GLOBALS['tmpl']->assign("list",$list);
		$GLOBALS['tmpl']->display("inc/store_ajax_get_content.html");
	}
	
	public function ajax_get_xianjin($count=0){
				convert_req($_REQUEST);	
				if(intval($_REQUEST['id'])==0)
				return false;
				$location_id = intval($_REQUEST['id']);
				$page_size=4;
				$pageArgs = array();
				
				//分页
				$page = intval($_REQUEST['p']);
				if($page==0)
					$page = 1;
				
				$GLOBALS['tmpl']->assign("page",$page);
				$limit = (($page-1)*$page_size).",".$page_size;	
				require_once APP_ROOT_PATH.'app/Lib/page.php';
				
				$x_sql_count = "select count(*) from ".DB_PREFIX."deal as d 
					left join ".DB_PREFIX."deal_location_link as l on l.deal_id = d.id 
					where d.is_delete = 0 and d.is_effect = 1 and d.is_shop = 2 and d.time_status in (0,1) and l.location_id = ".$location_id;
				$count = $GLOBALS['db']->getOne($x_sql_count);
				
				$pageArgs['ctl'] = "kview";
				$pageArgs['act'] = "ajax_get_xianjin";
				$pageArgs['id'] = intval($_REQUEST['id']);
				$pageArgs['count'] = $count;
				$pageArgs['is_ajax'] = "1";
				$url_parameter = http_build_query($pageArgs);
				$page = new Page($count,$page_size,$url_parameter);   //初始化分页对象 		
				$p  =  $page->show();
				$GLOBALS['tmpl']->assign('pages',$p);
				
				$d_sql = "select id,name,img,uname,current_price,origin_price,buy_count from ".DB_PREFIX."deal as d 
					left join ".DB_PREFIX."deal_location_link as l on l.deal_id = d.id 
					where d.is_delete = 0 and d.is_effect = 1 and d.is_shop = 2 and d.time_status in (0,1) and l.location_id = ".$location_id." order by d.sort desc limit ".$limit;
				$result_list = $GLOBALS['db']->getAll($d_sql);
				//print_r($result_list);
				foreach($result_list as $k=>$v)
				{
					if($v['uname']=='')				
					$result_list[$k]['url'] = url("store","ydetail",array("id"=>$v['id']));	
					else
					$result_list[$k]['url'] = url("store","ydetail",array("id"=>$v['uname']));	
					$result_list[$k]['format_origin_price']=round($v['origin_price'],2);
					$result_list[$k]['format_current_price']=format_price($v['current_price']);	
					$result_list[$k]['discount'] = round(($v['current_price']/$v['origin_price'])*10,2);	
				}
				$GLOBALS['tmpl']->assign("result_list",$result_list);
				$html = $GLOBALS['tmpl']->fetch("inc/store/store_ajax_get_xianjin.html");
				if($_REQUEST['is_ajax']=="1")
					echo $html;
				else
					return $html;
	}
	
	public function ajax_get_order($count = 0){
		convert_req($_REQUEST);	
		if(intval($_REQUEST['id'])==0)
			return false;
		
		$pageArgs = array();
		
		$page_size = 15;
		
		if(!isset($_REQUEST['field']) || empty($_REQUEST['field'])){
			$field = "create_time";
		}
		else{
			$field = $_REQUEST['field'];
		}
		
		if(!isset($_REQUEST['sort']) || empty($_REQUEST['sort'])){
			$sort = "DESC";
		}
		else{
			$sort = $_REQUEST['sort'];
		}
		
		//分页
		$page = intval($_REQUEST['p']);
		if($page==0)
			$page = 1;
		
		$GLOBALS['tmpl']->assign("page",$page);
		$limit = (($page-1)*$page_size).",".$page_size;	
		require_once APP_ROOT_PATH.'app/Lib/page.php';
		
		if($count == 0)
		{
			$count = $GLOBALS['db']->getOne("SELECT count(*) FROM ".DB_PREFIX."supplier_location_order WHERE status in(0,1,2) AND sid=".intval($_REQUEST['id']));
		}
		$pageArgs['ctl'] = "view";
		$pageArgs['act'] = "ajax_get_order";
		$pageArgs['id'] = intval($_REQUEST['id']);
		$pageArgs['field'] = $field;
		$pageArgs['sort'] = $sort;
		$pageArgs['count'] = $count;
		$pageArgs['is_ajax'] = "1";
		$url_parameter = http_build_query($pageArgs);
		$page = new Page($count,$page_size,$url_parameter);   //初始化分页对象 		
		$p  =  $page->show();
		$GLOBALS['tmpl']->assign('pages',$p);
	
		$list = $GLOBALS['db']->getAll("SELECT * FROM ".DB_PREFIX."supplier_location_order WHERE status in(0,1,2) AND sid=".intval($_REQUEST['id'])." ORDER BY $field $sort LIMIT ".$limit);
		//一周内的订单
		$start_time = get_gmtime() - (7*24*3600);
		$end_time = get_gmtime();
		$new_count = $GLOBALS['db']->getOne("SELECT count(*) FROM ".DB_PREFIX."supplier_location_order WHERE status in(0,1,2) AND sid=".intval($_REQUEST['id'])." AND create_time BETWEEN $start_time AND $end_time");
		$GLOBALS['tmpl']->assign("new_count",$new_count);
		$GLOBALS['tmpl']->assign("count",$count);
		$GLOBALS['tmpl']->assign("list",$list);
		
		$GLOBALS['tmpl']->assign("sort",$sort == "DESC" ? "ASC" : "DESC");
		
		$GLOBALS['tmpl']->assign("field",$field);
		$GLOBALS['tmpl']->assign("id",$_REQUEST['id']);
		
		$html = $GLOBALS['tmpl']->fetch("inc/store/store_ajax_get_order.html");
		if($_REQUEST['is_ajax']=="1")
			echo $html;
		else
			return $html;
	}
	
	
	
	
	function load_recent_sign($param)
	{
		$id = intval($param['id']);
		$time = get_gmtime();
		$begin_time = get_gmtime() - 3 * 24 * 3600;
		$end_time = get_gmtime() + 3 * 24 * 3600;

		$list = $GLOBALS['db']->getAll("select distinct(user_id) from ".DB_PREFIX."supplier_location_sign_log where location_id = $id and (sign_time between $begin_time and $end_time) order by sign_time desc limit 9 ");
		$count = $GLOBALS['db']->getOne("select count(distinct(user_id)) from ".DB_PREFIX."supplier_location_sign_log where location_id = $id and (sign_time between $begin_time and $end_time)  ");
		$GLOBALS['tmpl']->assign("list",$list);
		$GLOBALS['tmpl']->assign("count",$count);
		if($list)
		return $GLOBALS['tmpl']->fetch("inc/user_sign.html");
		else
		return ""; 
		
	}
	
	function load_default_date(){
		$now_time = get_gmtime();
				
		$default_hour = to_date($now_time,"H");
		if(intval($default_hour) >21){
			$now_time = $now_time +(3600*3);
		}
		$week = array('日','一','二','三','四','五','六'); 
		$default_date = to_date($now_time,"Y年m月d日") ." 星期".$week[to_date($now_time,"w")];
		
		return $default_date;
	}
	function load_default_hour(){
		$now_time = get_gmtime();
				
		$default_hour = to_date($now_time,"H");
		if((int)$default_hour > 9 && (int)$default_hour < 21){
			$default_hour = (int)$default_hour+1;
		}
		else{			
			$default_hour = 10;
		}
		return $default_hour."点";
	}
	function load_default_mini(){
		return "15分";
	}
	
	
}
?>